import random

def abeq(a,b):
    return abs(a-b)<1

def chase(x,y):
    if abs(x)>abs(y):
        if x>=0:
            return 4
        else:
            return 3
    else:
        if y>=0:
            return 2
        else:
            return 1

def ab_chase(x,y):
    if abs(x)>abs(y):
        if x>=0:
            return 3
        else:
            return 4
    else:
        if y>=0:
            return 1
        else:
            return 2  

def eat_food(obs):
    food_list=[]
    for ob in obs:
        if abeq(ob[4],255) :
            food_list.append(ob)

    food_list.sort(key=lambda ob : abs(ob[0])+abs(ob[1]))

    x,y=food_list[0][0],food_list[0][1]

    return chase(x,y)


def attack(obs):
    x,y,hp=get_rival(obs)
        
    if (x**2+y**2)<3600:
        return 5
    else :
        return chase(x,y)
    
def defense(obs):
    x,y,r=get_fireball(obs)
    if (x,y)==(0,0) or (x**2+y**2)>(r+50)**2:
        return eat_food(obs)
    else:
        return ab_chase(x,y)


def get_rival(obs):
    x,y,hp=0,0,0
    for ob in obs:
        if abeq(ob[3],150) and (not abeq(ob[0],0)) and (not abeq(ob[1],0)):
            x,y,hp=ob[0],ob[1],ob[7]
            break
    return x,y,hp

def get_self(obs):
    x,y,hp=0,0,0
    for ob in obs:
        if abeq(ob[3],150) and abeq(ob[0],0) and abeq(ob[1],0):
            x,y,hp=ob[0],ob[1],ob[7]
            break
    return x,y,hp

def get_fireball(obs):
    x,y,r=0,0,0
    for ob in obs:
        if abeq(ob[3],255) :
            x,y,r=ob[0],ob[1],ob[2]
            break
    return x,y,r



class Robot:
    is_attack=False

    def decide(self,obs):
        x1,y1,hp1=get_self(obs)
        x2,y2,hp2=get_rival(obs)

        if hp1-hp2>50:
            self.is_attack=True

        if hp1-hp2<0:
            self.is_attack=False
        
        if self.is_attack:
            return attack(obs)
        else:
            return defense(obs)
